package com.zfzs.post.controller;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.model.dto.*;
import com.zfzs.post.model.vo.AgentMineInfoVO;
import com.zfzs.post.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 用户信息控制器
 *
 * @author ck
 * @date 2018-11-23
 */
@Slf4j
@RestController
@RequestMapping("user/")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 注册
     */
    @Log("注册")
    @PostMapping(value = "registe")
    public ResponseResult registe(@Validated @RequestBody UseRegisterDTO dto) {
        Map<String, String> token = userService.registePhone(dto);
        return ResponseResult.ok("注册成功", token);
    }

    /**
     * 获取用户信息
     */
    @Log("获取用户详细信息")
    @PostMapping(value = "${jwt.auth.account}")
    public ResponseResult getUserInfo() {
        Map<String, Object> user = userService.getUserInfo();
        return ResponseResult.ok(user);
    }

    /**
     * 找回密码
     */
    @Log("找回密码")
    @PostMapping(value = "forget_pwd")
    public ResponseResult forgetPwd(@Validated @RequestBody ForgetPwdDTO dto) {
        userService.forgetPwd(dto);
        return ResponseResult.ok();
    }

    /**
     * 修改密码
     */
    @Log("修改密码")
    @PostMapping(value = "update_pwd")
    public ResponseResult updatePwd(@Validated @RequestBody UpdatePwdDTO dto) {
        userService.updatePwd(dto);
        return ResponseResult.okMsg("修改密码成功");
    }

    /**
     * 实名认证
     */
    @Log("实名认证")
    @PostMapping(value = "verified")
    public ResponseResult verified(@Validated @RequestBody VerifiedDTO dto) {
        userService.verified(dto);
        return ResponseResult.okMsg("实名认证成功");
    }

    /**
     * 修改结算卡信息
     */
    @Log("修改结算卡信息")
    @PostMapping(value = "update_bank_info")
    public ResponseResult updateBankInfo(@Validated @RequestBody UpdateSettleDTO dto) {
        userService.updateSettleInfo(dto);
        return ResponseResult.okMsg("结算卡修改成功");
    }

    /**
     * 修改身份证号码
     */
    @Log("修改身份证号码")
    @PostMapping(value = "update_card_no")
    public ResponseResult updateIDCardNo(@Validated @RequestBody UpdateIDCardNoDTO dto) {
        userService.updateIDCardNo(dto);
        return ResponseResult.okMsg("身份证号码修改成功");
    }

    /**
     * 修改手机号码
     */
    @Log("修改手机号码")
    @PostMapping(value = "update_phone")
    public ResponseResult updatePhone(@Validated @RequestBody UpdatePhoneDTO dto) {
        userService.updatePhone(dto);
        return ResponseResult.okMsg("手机号码修改成功");
    }

    /**
     * 修改身份证姓名
     */
    @Log("修改身份证姓名")
    @PostMapping(value = "update_card_name")
    public ResponseResult updateIDCardName(@Validated @RequestBody UpdateIDCardNameDTO dto) {
        userService.updateIDCardName(dto);
        return ResponseResult.okMsg("身份证姓名修改成功");
    }

    /**
     * 修改提现密码
     */
    @Log("修改体现密码")
    @PostMapping(value = "update_withdraw_pwd")
    public ResponseResult updateWithdrawPwd(@Validated @RequestBody UpdatePwdDTO dto) {
        userService.updateWithdrawPwd(dto);
        return ResponseResult.okMsg("提现密码修改成功");
    }

    /**
     * 找回提现密码
     */
    @Log("找回提现密码")
    @PostMapping(value = "forget_withdraw_pwd")
    public ResponseResult forgetWithdrawPwd(@Validated @RequestBody ForgetPwdDTO dto) {
        userService.forgetWithdrawPwd(dto);
        return ResponseResult.okMsg("找回密码成功");
    }

    /**
     * 获取下级客户的信息
     *
     * @return
     */
    @Log("获取下级客户的信息")
    @PostMapping(value = "get_sub_agent_list")
    public ResponseResult getSubAgentList() {
        Map<String, Object> map = userService.getSubAgentList();
        return ResponseResult.ok(map);
    }

    /**
     * 根据姓名或者手机号码搜索
     */
    @Log("根据姓名或者手机号码搜索")
    @PostMapping(value = "get_agent_bykey")
    public ResponseResult getAgentListByKeywords(@Validated @RequestBody QueryAgnetListDTO dto) {
        Map<String, Object> map = userService.getAgentListByKeywords(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 根据直营或者合伙人查询
     */
    @Log("根据直营或者合伙人查询")
    @PostMapping(value = "get_agent_list")
    public ResponseResult getAgentByIdsList(@Validated @RequestBody QueryAgnetTypeListDTO dto) {
        Map<String, Object> map = userService.getAgentByIdsList(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 查询所有下级列表
     */
    @Log("查询所有下级列表")
    @PostMapping(value = "get_all_child")
    public ResponseResult getAllChild() {
        Map<String, Object> map = userService.getAllChild();
        return ResponseResult.ok(map);
    }


    /**
     * 团队列表查询
     */
    @Log("团队列表查询")
    @PostMapping(value = "get_agent_page_list")
    public ResponseResult getAgentPageList(@Validated @RequestBody QueryAgentPageListDTO dto) {
        Map<String, Object> map = userService.getAgentPageList(dto);
        return ResponseResult.ok(map);
    }

    /**
     * 修改头像
     */
    @Log("修改头像")
    @PostMapping(value = "update_head_img")
    public ResponseResult updateHeadImg(@Validated @RequestBody IdDTO dto) {
        userService.updateheadImg(dto);
        return ResponseResult.okMsg("头像修改成功");
    }

    /**
     * 我的信息
     *
     * @return
     */
    @Log("我的页面信息")
    @PostMapping(value = "get_mine_info")
    public ResponseResult myIndexInfo() {
        AgentMineInfoVO info = userService.myIndexInfo();
        return ResponseResult.ok(info);
    }

    /**
     * 新增成员
     *
     * @param addAgentDTO
     * @return
     */
    @Log("新增成员")
    @PostMapping(value = "add_agent")
    public ResponseResult addAgent(@RequestBody AddAgentDTO addAgentDTO) {
        userService.addAgentByUpper(addAgentDTO);
        return ResponseResult.okMsg("新增成员成功");
    }

    /**
     * 类型数据
     */
    @Log("团队类型")
    @PostMapping(value = "get_team_list")
    public ResponseResult getTeamList() {
        Map<String, Object> map = userService.getTeamList();
        return ResponseResult.ok(map);
    }

    /**
     * 团队排名
     *
     * @param query
     * @return
     */
    @Log("团队排名")
    @PostMapping(value = "get_team_rank_page")
    public ResponseResult getTeamRankPage(@Validated @RequestBody QueryTeamRankPageDTO query) {
        Map<String, Object> map = userService.getTeamRankPage(query);
        return ResponseResult.ok(map);
    }
}
